<?php 
/**
 *	GChart.php
 *
 * 	This program is free software: you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License as published by
 *	the Free Software Foundation, either version 3 of the License, or
 *	(at your option) any later version.
 *
 *	This program is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public License for more details.
 *
 *	You should have received a copy of the GNU General Public License
 *	along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *	@filesource
 *	@package	GChart
 *	@category	Charts
 *	@version	0.1.0
 *	@license	http://www.gnu.org/licenses/gpl-3.0.txt
 *	@copyright	Copyright (c) 2009 Daniel Morris
 *	@link		http://code.google.com/p/gchart-php/
 *	@author		Daniel Morris
*/
class GChart {

	/**
	 *	The Base URI to the Google Chart API.
	*/
	const BASE_URI = 'http://chart.apis.google.com/chart?';

	/**
	 *	An array containing the URL parameters that will
	 *	be sent to the Google Chart API.
	 *
	 *	@var	array
	 *	@since	0.1.0
	*/
	protected $_params = array();
	
	/**
	 *	Set the chart data.
	 *
	 *	@param	mixed
	 *	@return	integer
	 *	@since	0.1.0
	 *	@author	Daniel Morris
	*/
	public function data () {
		$count = 0;
		foreach (func_get_args() as $a) {
			if (is_numeric($a)) {
				$this->_params['chd=t:'][] = $a;
				$count++;
			} elseif (is_array($a)) {
				foreach ($a as $v) {
					$this->data($v);
					$count++;
				}
			}
		}
		return $count;
	}
	
	/**
	 *	Set the chart size.
	 *
	 *	@param	integer
	 *	@param	integer
	 *	@since	0.1.0
	 *	@author	Daniel Morris
	*/
	public function size ($x, $y) {
		if (is_integer($x) && is_integer($y)) {
			$this->_params['chs'] = "{$x}x{$y}";
		}
	}
	
	/**
	 *	Display the chart.
	*/
	public function display () {
		$url_params = array();
		foreach ($this->_params as $k => $v) {
			if (is_string($v)) {
				$url_params[] = "{$k}={$v}";
			} elseif (is_array($v)) {
				$url_params[] = $k.implode(',', $v);
			}
		}
		echo '<img src="', 
			 self::BASE_URI.implode('&amp;', $url_params), 
			 '" />';
	}

}
/**
 *	@since	0.1.0
 *	@author	Daniel Morris
*/
class GChart_Line extends GChart {

	/**
	 * 	Constructor
	 *
	 *	@author	Daniel Morris
	*/
	public function __construct () {
		$this->_params['cht'] = 'lc';
	}
	
	/**
	 *	@param	boolean
	 *	@since	0.1.0
	 *	@author	Daniel Morris
	*/
	public function showAxis ($showAxis = true) {
		$showAxis == true ? $cht = 'lc' : $cht = 'ls';
		$this->_params['cht'] = $cht;
	}
	
	/**
	 *	@param	string
	 *	@since	0.1.0
	 *	@author	Daniel Morris
	*/
	public function setLineColor ($color) {
		$this->_params['chco'] = $color;
	}

}
?>